package cn.jbit.stream.fastjson;

import cn.jbit.stream.pojo.User;
import com.alibaba.fastjson.JSONArray;
import org.junit.jupiter.api.Test;

public class JsonTest {

    @Test
    public  void  testObjectJson(){

        User user=new User();
        user.setId(30);
        user.setName("张杰");
        user.setPassword("123.com");
        String s = JSONArray.toJSONString(user);
        System.out.println(s);

    }

    /**
     * 字符串转成User对象
     */
    @Test
    public void testUnSerialJson(){

        String json="{\"id\":1,\"name\":\"张三\",\"password\":\"123.com\"}";

        User user = JSONArray.parseObject(json, User.class);

        System.out.println(user);


    }

}
